package com.ruoyi.web.controller.app;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IHgtLogService;
import com.ruoyi.system.service.ISysCfcaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;


@RestController
@RequestMapping("/hgtlog")
public class hgtlogController {

    @Autowired
    private IHgtLogService hgtLogService;

    @PostMapping ("logsave")
    HashMap<Object, Object> qzsave( @RequestBody HgtLog hgtLog) {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();
        HgtLog bb = hgtLogService.selectHgtLogByname(hgtLog);
        if(bb!=null) {
            aa.put("code",0);
            bb.setTxdesc(hgtLog.getTxdesc());
            hgtLogService.updateHgtLog(bb);
            aa.put("msg","已有今日日志，更新日志");
        }else{
            aa.put("code",0);
            aa.put("msg","提交成功");
            hgtLogService.insertHgtLog(hgtLog);
        }

        map.put("data",aa);
        return map;
    }
    @PostMapping ("tjline")
    HashMap<Object, Object> tjline( @RequestBody HgtLog hgtLog) {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();
        List<HgtLogsum> bb = hgtLogService.selectHgtLogcount(hgtLog.getTxdate());
        String namex[] = new String[bb.size()];
        Integer namey[] = new Integer[bb.size()];
        for(int i=0;i<bb.size();i++){
            namex[i]=bb.get(i).getNamex();
            namey[i]=bb.get(i).getNamey();
        }
        aa.put("code",0);
        aa.put("msg","提交成功");
        aa.put("namex",namex);
        aa.put("resultData",bb);
        aa.put("namey",namey);
        map.put("data",aa);
        return map;
    }
    @PostMapping ("tjlinesum")
    HashMap<Object, Object> tjlinesum( @RequestBody HgtLog hgtLog) {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();
        List<HgtLogsum> bb = hgtLogService.selectHgtLogsum(hgtLog.getCeater());
        String namex[] = new String[bb.size()];
        Integer namey[] = new Integer[bb.size()];
        for(int i=0;i<bb.size();i++){
            namex[i]=bb.get(i).getNamex();
            namey[i]=bb.get(i).getNamey();
        }
        aa.put("code",0);
        aa.put("msg","提交成功");
        aa.put("resultData",bb);
        aa.put("namex",namex);
        aa.put("namey",namey);
        map.put("data",aa);
        return map;
    }
    @PostMapping("findhgtlog")
    HashMap<Object, Object> findhgtlog(@RequestBody HgtLog hgtLog) {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();
        if(hgtLog.getIphonerole().equals("saaslead")){
            hgtLog.setCeater("");
            hgtLog.setIphonerole("saas");
        }
        List<HgtLog> hgtLoglist = hgtLogService.selectHgtLogList(hgtLog);
        aa.put("code",0);
        aa.put("msg","提交成功");
        aa.put("resultData",hgtLoglist);
        map.put("data",aa);
        return map;
    }
    @PostMapping("findhgtlogtask")
    HashMap<Object, Object> findhgtlogtask() {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap<Object, Object> aa = new HashMap<>();

       /* List<HgtLog> hgtLoglist = hgtLogService.selectHgtLogList(hgtLog);*/
        aa.put("code",0);
        aa.put("msg","提交成功");
        aa.put("resultData","");
        map.put("data",aa);
        return map;
    }


}
